import { getGalleryList } from "@/api/home";

export default class UseGalleryList {
  public optionsList = ["全部", "建筑设计", "规划设计", "室内设计", "景观设计"]; // 类型
  public currentOptions = ref("全部");
  public loading = ref<boolean>(false);
  public noMore = ref<boolean>(false);
  public keyWord = ref(""); // 搜索条件
  pageOptions = ref({
    pageSize: 20,
    pageNum: 1,
  });
  public galleryList = ref<any[]>([]); // 列表

  // 查询灵感画廊列表
  queryGalleryList = async (reset = true) => {
    try {
      this.loading.value = true;
      this.noMore.value = false;
      const data = await getGalleryList(
        {
          labelQuery: this.currentOptions.value === "全部" ? "" : this.currentOptions.value,
          vagueQuery: this.keyWord.value,
        },
        this.pageOptions.value,
      );
      if (reset) {
        this.galleryList.value = data.rows || [];
      } else {
        this.galleryList.value = [...this.galleryList.value, ...data.rows];
      }
      if (!data.rows.length || data.rows.length < this.pageOptions.value.pageSize) {
        this.noMore.value = true;
      }
    } catch (err) {
      console.error(err);
      this.galleryList.value = [];
    } finally {
      this.loading.value = false;
    }
  };
}
